package com.desay.pangoo.itmt.entity;

import java.io.Serializable;
import java.util.Objects;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.Data;

/**
 * work group road map
 * 
 * @author uidq1163
 *
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "key_tech_roadMap")
@Data
public class KeyTechRoadMapEntity extends BaseEntity implements Serializable {

	private static final long serialVersionUID = -2662139657664983658L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", columnDefinition = "bigint COMMENT '主键'")
	private Long id;

	@Column(name = "tech_name", nullable = false, columnDefinition = "varchar(255) COMMENT '技术名称'")
	private String techName;

	@Column(name = "tech_ptn", nullable = true, columnDefinition = "varchar(255) COMMENT '技术编号'")
	private String techPtn;

	@Column(name = "project_info", nullable = true, columnDefinition = "varchar(255) COMMENT '技术项目名称'")
	private String projectInfo;

	@Column(name = "release_status", nullable = true, columnDefinition = "varchar(50) COMMENT '达成状态：OPEN，closed'")
	private String releaseStatus;

	@Column(name = "year", nullable = true, columnDefinition = "int COMMENT '时间：年'")
	private Long year;

	@ManyToOne(fetch = FetchType.EAGER, optional = true)
	@JoinColumn(name = "work_group_id")
	private WorkGroupEntity workGroup;

	@ManyToOne(fetch = FetchType.EAGER, optional = true)
	@JoinColumn(name = "parent_id")
	@JsonIgnoreProperties({ "phases" })
	private KeyTechRoadMapEntity parent;

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "parent")
	@JsonIgnoreProperties({ "parent" })
	private Set<KeyTechRoadMapEntity> phases;

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!super.equals(obj)) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		KeyTechRoadMapEntity other = (KeyTechRoadMapEntity) obj;
		return Objects.equals(projectInfo, other.projectInfo) && Objects.equals(releaseStatus, other.releaseStatus)
				&& Objects.equals(techName, other.techName) && Objects.equals(techPtn, other.techPtn)
				&& Objects.equals(workGroup, other.workGroup) && Objects.equals(year, other.year);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + Objects.hash(projectInfo, releaseStatus, techName, techPtn, workGroup, year);
		return result;
	}

}
